// pages/goodcomment/goodcomment.js
Page({
  data: {
    scoreType: -1,
    page: 1,
    total: {},
    goodCommentList: []
  },
  onLoad(query) {
    this.setData({goodsId: query.goodsId})
    this.getGoodCommentList()
    this.getGoodCommentTotal()
  },
  // 获取评价列表
  async getGoodCommentList() {
    const res = await wx.http.get('/comment/list', {
      scoreType: this.data.scoreType,
      goodsId: this.data.goodsId,
      page: this.data.page
    })
    const goodCommentList = res.data.data.list.data
    this.setData({goodCommentList})
  },
  // 获取评价数量
  async getGoodCommentTotal() {
    const res = await wx.http.get('/comment/total', {goodsId: this.data.goodsId})
    const total = res.data.data.total
    this.setData({total})
  },
  // 点击tab栏切换评价类型
  onTabsClick(ev) {
    this.setData({
      scoreType: ev.detail.value
    })
    this.getGoodCommentList()
  }
})